angular.module("app.stat").register.controller("ListProjectSmsCtrl", ["$scope", "$http", "$state", "$modal", "$modalService", function($scope, $http, $state, $modal, $modalService){
  $scope.stores = [];
  //@formatter:off
  $scope.opts = {
    status: [{k: '', t: '请选择'}, {k: 1, t: '成功'}, {k: 0, t: '失败'}],
    projects: [{id: '', name: '请选择项目'}]
  };
  //@formatter:on
  $scope.pager = {
    sizeOpts: [5, 10, 15, 20, 25, 30],
    size: 15,
    maxSize: 5,
    records: 0,
    page: 1,
    onChangeSize: function(){
      $scope.pager.page = 1;
      $scope.gets(1);
    },
    onChange: function(page){
      $scope.gets(page);
    },
    total: function(){
      return Math.ceil($scope.pager.records / $scope.pager.size);
    }
  };
  $scope.openDatepicker = function($event, attr){
    $event.preventDefault();
    $event.stopPropagation();
    $scope[attr] = !0;
  };
  $scope.filter = {
    mobile: '',
    status: '',
    project_id: '',
    start_date: '',
    end_date: ''
  };
  $scope.getCount = function(){
    $http.post('/project/sms/count', {
      filter: $scope.filter
    }, {
      transformRequest: function(data){
        return $.param(data);
      }
    }).success(function(ret){
      if(ret.status){
        $scope.pager.records = ret.data;
      }else{
        $modalService.myAlert(ret.data);
      }
    }).error(function(){
      $modalService.myAlert('系统错误，请求资源失败！');
    });
  };
  $scope.gets = function(page){
    $scope.loadTip = '正在获取数据...........';
    $scope.stores = [];
    $http.post('/project/sms/gets', {
      page: page,
      size: $scope.pager.size,
      filter: $scope.filter
    }, {
      transformRequest: function(data){
        return $.param(data);
      }
    }).success(function(ret){
      if(ret.status){
        $scope.stores = ret.data;
        $scope.stores.length == 0 ? $scope.loadTip = '没有找到相关记录！！' : '';
      }else{
        $modalService.myAlert(ret.data);
      }
    }).error(function(){
      $modalService.myAlert('系统错误，请求资源失败！');
    });
  };
  $scope.getProject = function(){
    $http.post('/project/index/getkvs/sms/', {}, {
      transformRequest: function(data){
        return $.param(data);
      }
    }).success(function(ret){
      if(ret.status){
        $.each(ret.data, function(k, v){
          $scope.opts.projects.push(v);
        });
        $scope.filter.project_id = '';
      }else{
        $modalService.myAlert(ret.data);
      }
    }).error(function(){
      $modalService.myAlert('系统错误，请求资源失败！');
    });
  }
  $scope.refresh = function(){
    $scope.stores = [];
    $scope.getCount();
    $scope.gets($scope.pager.page);
  };
  $scope.search = function(){
    $scope.pager.page = 1;
    $scope.refresh();
  }
  $scope.initialize = function(){
    $scope.getProject();
    $scope.gets(1);
    $scope.getCount();
  };
  $scope.initialize();
}]);
angular.module("app.stat").register.controller("ViewCaptchaCtrl", ["$scope", "$modalInstance", "data", function($scope, $modalInstance, data){
  $scope.entity = data;
  $scope.cancel = function(){
    $modalInstance.dismiss("cancel");
  };
}]);




